package com.wr.hangzhounewlight.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wr.hangzhounewlight.obj.database.OutputMasterEntity;
import com.wr.hangzhounewlight.obj.dto.frontend.OutputSelectDTO;
import com.wr.hangzhounewlight.obj.vo.frontend.OutputSelectVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author yuanzhizhuo
 * createDate 2025/11/3
 */
public interface OutputMasterMapper extends BaseMapper<OutputMasterEntity> {

    @Insert("""
            insert ignore into output_master (id, order_id, count)
            values (#{id}, #{orderId}, #{count});
            """)
    int insertIgnore(String id, String orderId, int count);

    @Select("""
            select t1.machine, t1.screw, t2.order_no, t3.id as output_master_id,  t3.count, t3.insert_time
            from device as t1
                     left join `order` as t2 on t1.id = t2.device_id
                     left join output_master as t3 on t2.id = t3.order_id
            where t1.workshop = #{workshop}
              and t1.machine = #{machine}
              and t1.screw = #{screw}
              and t2.order_no = #{orderNo}
              and t3.insert_time between #{startDateTime} and #{endDateTime}
            order by t3.insert_time;
            """)
    List<OutputSelectVO> selectOutputVO(OutputSelectDTO dto);

}
